package com.windgo.controller.admin;

import com.windgo.bean.MarketUser;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * @param info
     * @param username
     * @param mobile
     * @return com.windgo.bean.common.BaseRespVo
     * @author mabai
     * @since 2022/10/12 21:25
     */
    @RequestMapping("list")
    @RequiresPermissions("perms[admin:user:list]")
    public BaseRespVo list(BasePageInfo info, String username, String mobile) {
        CommonData<MarketUser> data = userService.list(info, username, mobile);
        return BaseRespVo.ok(data);
    }
    @PostMapping("update")
    @RequiresPermissions("perms[admin:user:update]")
    public BaseRespVo update(@RequestBody MarketUser marketUser){
        int code = userService.updateUserInfo(marketUser);
        if (code == 200){
            return BaseRespVo.ok(1);
        }
        return BaseRespVo.ok(1,"编辑会员信息失败");
    }
}
